var OrderDownload = Vue.component('orderDownload', function (resolve, reject) {
    axios.get('views/orderDownload/orderDownload.html?timestamp=' + timestamp).then(function (res) {
        resolve({
            template: res.data,
            data() {
                return {
                    tableData: [],
                    dialogFormVisible: false,
                    form: {},
                    searchForm: {},
                    searchOptions: {
                        lifeManagerUser: [],
                        salesUser: [],
                        life: [],
                        orderStatusSearchOptions: [],
                        product: []
                    },
                    pageInfo: {
                        currentPage: 1,
                        pageSize: 10,
                        srch_EQ_delete: false,
                        totalPage:1
                    },
                    formLabelWidth: '120px',
                    permssion: {},
                    buttomPermission: {
                        searchSales: [admin, alipayManager,access],
                        searchLifeManager: [admin,access],
                        lifeManagerAndSaler: [alipayManager,sales,admin]
                    },
                    showSteps: false,
                    orderStatusJson:{},
                    detailData:{},
                    gridData :{},
                    detailDialog:false,
                    fileAction:APIs.order.upload,
                    uploadHead:{token:sessionStorage.token},
                    uploadFileName:"",
                    dialogVisible:false,
                    dialogVisibleMsg:"",
                    sentDialogFormVisible:false,
                    cancelDialogFormVisible:false,
                    sentForm:{},
                    YesOrType:{"1":"是","0":"否"},
                    stepList:[],
                    newOrderStatusLog:{},
                    checkCountInterval:null

                   
                }
            },
            methods: {
                onSubmit: function () {
                    console.log(this.searchForm);
                    // this.pageInfo.currentPage=1;
                    this.$set(this.pageInfo,'currentPage',1);
                },
                checkPermission: function (type) {
                    let checkArr = this.buttomPermission[type];
                    if (checkArr) {
                        for (var v in checkArr) {
                            if (this.permssion[checkArr[v]]) {
                                return true;
                            }
                        }
                    } else {
                        return true;
                    }
                    return false;
                },
                getPageConfig: function () {
                    httpInvoker.get(APIs.order.config)
                        .then(res => {
                            if (res.status == 200 && res.data.status == '00') {
                                var data = res['data'];
                                if (data.status == '00') {
                                    this.$set(this.searchOptions, 'lifeManagerUser', (data['data'].lifeManagerUser ? data['data'].lifeManagerUser : []));
                                    this.$set(this.searchOptions, 'salesUser', (data['data'].salesUser ? data['data'].salesUser : []));
                                    this.$set(this.searchOptions, 'life', (data['data'].life ? data['data'].life : []));
                                    this.$set(this.searchOptions, 'orderStatusSearchOptions', (data['data'].orderStatusSearchOptions ? data['data'].orderStatusSearchOptions : []));
                                    if(this.searchOptions.orderStatusSearchOptions){
                                        this.searchOptions.orderStatusSearchOptions.forEach(element => {
                                            this.$set(this.orderStatusJson, element['value'], element['label']);

                                        });
                                    }

                                }
                               
                            } else {
                                this.$alert(res.data.msg, '', {
                                    confirmButtonText: '确定'
                                });
                            }
                           
                        })
                  
                },
                changeSelect: function (type) {
                    if ('lifeManager' == type) {
                        this.$set(this.searchForm, 'life', null)
                    }
                    this.$set(this.searchForm, 'product', null)
                    this.$set(this.searchForm, 'saler', null)
                    httpInvoker.post(APIs.order.config + "/" + type, this.searchForm)
                        .then(res => {
                            this.logining = false;
                            if (res.status == 200 && res.data.status == '00') {
                                var map = res['data'];
                                if (map.status == '00') {
                                    var data = map['data'];
                                    var salesUser = data['salesUser'];
                                    var life = data['life'];
                                    var product = data['productList'];
                                    if ('lifeManager' == type) {
                                        this.$set(this.searchOptions, 'life', (life ? life : []))
                                    } else if ('life' == type) {

                                    }
                                    this.$set(this.searchOptions, 'product', (product ? product : []))
                                    this.$set(this.searchOptions, 'salesUser', (salesUser ? salesUser : []))
                                }

                            } else {
                                this.$alert(res.data.msg, '', {
                                    confirmButtonText: '确定'
                                });
                            }
                        })
                } ,download(){
                    var ps  = '';
                    for(key in this.searchForm){
                        ps+="&"+key+"="+(this.searchForm[key]==null?"":this.searchForm[key]);
                    }
                    var url = APIs.order.report+"?downLoadId="+sessionStorage.token;
                    url+=ps;
                    window.open(url, '_blank');
                }
                 
            },
            created: function () {
                var json = CommonUtils.getPermissionJson();
                this.permssion = json;
                this.getPageConfig();
               
            },destroyed:function(){
                
            }
            
        })
    })
})